package com.ruoyi.project.tool.swagger.UserController;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.aspectj.lang.annotation.SignatureValidation;
import com.ruoyi.framework.interceptor.annotation.RepeatSubmit;
import com.ruoyi.framework.redis.RedisCache;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.system.domain.SysMobileUser;
import com.ruoyi.project.system.domain.SysUserService;
import com.ruoyi.project.system.service.ISysMobileUserService;
import com.ruoyi.project.system.service.ISysUserServiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/mobileUser/addType/")
public class UserAddTypeController {

    @Autowired
    private ISysUserServiceService sysUserServiceService;
    /**
     *  用户添加收藏
     *  传 物品详情ID
     * */
    @SignatureValidation
    @PostMapping("/insertType")
    public AjaxResult insertType(@RequestBody SysUserService sysUserService){
        Long mobileUserId = SecurityUtils.getLoginUser().getSysMobileUser().getMobileUserId();
        sysUserService.setMobileUserId(mobileUserId);
        sysUserService.setDelFlag("0");
        SysUserService sysService = sysUserServiceService.queryRepeat(sysUserService);
        if(sysService != null ){
            return AjaxResult.error("该物品已经被收藏了");
        }

        return AjaxResult.success(sysUserServiceService.insertSysUserService(sysUserService));
    }

    /**
     * 用户查看自己的收藏服务
     * */
    @SignatureValidation
    @GetMapping("queryMyService")
    public AjaxResult queryMyService(SysUserService sysUserService){
        Long mobileUserId = SecurityUtils.getLoginUser().getSysMobileUser().getMobileUserId();
        return AjaxResult.success(sysUserServiceService.queryMyService(mobileUserId));
    }

    /**
     * 用户删除自己的收藏服务
     * */
    @SignatureValidation
    @RepeatSubmit
    @PostMapping("deleteMyService")
    public AjaxResult deleteService(@RequestBody SysUserService sysUserService){
        Long mobileUserId = SecurityUtils.getLoginUser().getSysMobileUser().getMobileUserId();
        sysUserService.setMobileUserId(mobileUserId);
       return AjaxResult.success(sysUserServiceService.deleteMyService(sysUserService));
    }
    /**
     * 用户清空收藏服务
     * */
    @SignatureValidation
    @GetMapping("deleteAllService")
    public AjaxResult deleteAllService(SysUserService sysUserService){
        Long mobileUserId = SecurityUtils.getLoginUser().getSysMobileUser().getMobileUserId();
        sysUserService.setMobileUserId(mobileUserId);
        return AjaxResult.success(sysUserServiceService.deleteAllService(sysUserService));
    }
}
